jQuery(function($){
	jQuery("#datagrid").jqGrid({
	    url:'listSystem.action?system.valid_flag=1',  
	    mtype: "POST",
	    datatype: "json",
	    colNames:['系统编码', '系统名称', '已启用', '系统路径', '创建日期', '修改日期'],
	    colModel:[
            {name:'system_code',index:'system_code',align:'center'},
	        {name:'system_name',index:'system_name'},
	        {name:'used_flag',index:'used_flag',align:'center',
	        	formatter:function(value,col,record) {
	        		if(value=='1') {
	        			return "是";
	        		}
	        		else {
	        			return "否";
	        		}
	        	}
	        },
	        {name:'system_url',index:'system_url'},
	        {name:'create_time',index:'create_time',datefmt:'Y-m-d'},
	        {name:'modify_time',index:'modify_time',datefmt:'Y-m-d'}	
	    ],
	    jsonReader: {
	    	root: "results",
	    	total: "totalpages",
	    	page: "currpage",
	    	records: "totalrecords",
	    	repeatitems: false
	    },
	    pager: '#pager',
	    sortname: 'user_code',
	    multiselect: true,
	    viewrecords: true,
	    sortorder: "ASC",
	    caption: "系统列表",
	    autowidth: true,
	    height: '100%',
	    ondblClickRow: function(id, ri, ci, e){
	    	loadSystem(id);
	    }
	});
	
	jQuery("#datagrid").navGrid(
		'#page',
		{add:false, edit:false, del:true, search:false, refresh:true},
		{},{},
		{
			modal:true,url:"updateValid.action?system.valid_flag=0",
			afterSubmit:function(data, params){
				if(data.responseText) {
					var obj = eval('('+ data.responseText +')');
					var msg = obj.message?obj.message:((obj.success==true || obj.success=='true')?"系统信息删除成功！":"系统信息删除失败！");
					return [obj.success, msg];
				} else {
					return [true];
				}
			}
		},{},{}
	);
});

function loadSystem(system_code) {
	showMDialog('loadSystem.action?edit=true&system.system_code='+system_code,'dialogWidth=900px;dialogHeight=600px');
//	window.open('loadSystem.action?edit=true&system.system_code='+system_code);
}

function gridReload(){
//	var user_code = jQuery("#search_user_code").val(); 
//	var department_name = jQuery("#search_department_name").val();
//	jQuery("#datagrid").jqGrid('setGridParam',{url:"listUser.action?user.valid_flag=1",postData:{"user.user_code":user_code,"user.department_name":department_name},page:1}).trigger("reloadGrid");
	jQuery("#datagrid").trigger("reloadGrid");
}